package com.cqupt.controller;

import com.cqupt.model.pojo.Scene;
import com.cqupt.model.pojo.SceneCategory;
import com.cqupt.model.pojo.SceneDetail;
import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import com.cqupt.model.vo.SceneChatVO;
import com.cqupt.model.vo.SpeakVO;
import com.cqupt.service.SceneCategoryService;
import com.cqupt.service.SceneService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/scene")
@Tag(name = "场景对话模块")
public class SceneController {

    @Resource
    private SceneService sceneService;


    @Resource
    private SceneCategoryService sceneCategoryService;

    @GetMapping("/sceneCategory")
    @Operation(summary = "显示所有场景分类")
    public Result sceneCategory() {
        List<SceneCategory> list = sceneCategoryService.list();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/all")
    @Operation(summary = "显示所有场景")
    public Result all() {
        List<Scene> list = sceneService.all();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/sceneList")
    @Operation(summary = "根据场景分类id显示场景")
    public Result sceneList(@RequestParam int categoryId) {
        List<Scene> list = sceneService.sceneList(categoryId, null, null).getRecords();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/scene")
    @Operation(summary = "选择场景")
    public Result chooseScene(@RequestParam int id) {
        SceneDetail sceneDetail = sceneService.chooseScene(id);
        return Result.build(sceneDetail, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/start")
    @Operation(summary = "开始场景对话")
    public Result startChat(@RequestParam int id) {
        SceneChatVO res = sceneService.startChat(id);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }


    @PostMapping("/chat")
    @Operation(summary = "情景对话")
    public Result chat(@RequestParam("file") MultipartFile file) {
        SpeakVO res = sceneService.chat(file);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }


    @PostMapping("/sendMsg")
    @Operation(summary = "发送消息")
    public Result sendMessage(@RequestParam("file") MultipartFile file) {
        SpeakVO res = sceneService.sendMessage(file);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/waitMsg")
    @Operation(summary = "等待回复消息")
    public Result waitMsg(@RequestParam String msg) {
        SpeakVO res = sceneService.waitMsg(msg);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/AiPrompts")
    @Operation(summary = "获取对话提示")
    public Result AiPrompts(@RequestParam String msg) {
        String res = sceneService.getAiPrompts(msg);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/check")
    @Operation(summary = "语法纠错")
    public Result check(@RequestParam String msg) {
        String res = sceneService.check(msg);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }
}
